import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/views/layout/index.vue'

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: { title: '登录' }
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/register/index.vue'),
    meta: { title: '注册' }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '首页', icon: 'dashboard', permission: 'dashboard:view' }
      },
      {
        path: 'user',
        name: 'User',
        redirect: '/user/list',
        meta: { title: '用户管理', icon: 'user', permission: 'user:manage' },
        children: [
          {
            path: 'list',
            name: 'UserList',
            component: () => import('@/views/user/list.vue'),
            meta: { title: '用户列表', permission: 'user:manage' }
          }
        ]
      },
      {
        path: 'book',
        name: 'Book',
        redirect: '/book/list',
        meta: { title: '图书管理', icon: 'reading', permission: 'book:manage' },
        children: [
          {
            path: 'list',
            name: 'BookList',
            component: () => import('@/views/book/list.vue'),
            meta: { title: '图书列表', permission: 'book:manage' }
          },
          {
            path: 'borrow',
            name: 'BookBorrow',
            component: () => import('@/views/book/borrow.vue'),
            meta: { title: '图书借阅', permission: 'book:borrow' }
          }
        ]
      },
      {
        path: 'borrow',
        name: 'Borrow',
        redirect: '/borrow/list',
        meta: { title: '借阅管理', icon: 'document', permission: 'borrow:manage' },
        children: [
          {
            path: 'list',
            name: 'BorrowList',
            component: () => import('@/views/borrow/list.vue'),
            meta: { title: '借阅记录', permission: 'borrow:manage' }
          }
        ]
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router 
